<#include "/client/config.ftl"/>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>我的信息</title>
		<link rel="stylesheet" href="${base}/css/bootstrap.min.css" />
		<script type="text/javascript" src="${base}/js/jquery-1.12.0.min.js"></script>
		<link rel="stylesheet" href="${base}/css/common.css" />
		<script type="text/javascript" src="${base}/js/string.js" ></script>
	</head>

	<body>
		<div class="container-fluid">
			<form action="${base}/client/medic/add" method="post">
			<#if medic?exists>
				<fieldset disabled>
			</#if>
			<ul>
				<li class="list_each">
					<div class="item">
						<span class="key">药名：</span>
						<span class="value">
							<#if medic?exists>
								<input type="text" name="medicName" value="${medic.medicName}" class="form-control" />
							<#else>
								<input type="text" name="medicName" placeholder="请输入药名" class="form-control" />
							</#if>
						</span>
					</div>
				</li>
				<li class="list_each">
					<div class="item">
						<span class="key">服用方式：</span>
						<span class="value">
							<#if medic?exists>
								<select name="takeType" class="form-control">
									<option value="${medic.takeType}">${medic.takeType}</option>
								</select>
							<#else>
								<select name="takeType" class="form-control">
									<option value="口服">口服</option>
									<option value="注射">注射</option>
									<option value="舌下吞服">舌下吞服</option>
									<option value="泡水服">泡水服</option>
									<option value="嚼碎服">嚼碎服</option>
									<option value="漱口">漱口</option>
									<option value="喷雾">喷雾</option>
									<option value="气雾">气雾</option>
									<option value="干粉吸入">干粉吸入</option>
									<option value="阴道放入">阴道放入</option>
									<option value="直肠放入">直肠放入</option>
								</select>
							</#if>
						</span>
					</div>
				</li>
			</ul>
			<#if medic?exists>
				</fieldset>
			</#if>
			<div class="page-header">
				<h1 class="text_left">
					<a href="#" id="alert_click">
						<span class="glyphicon glyphicon-plus-sign"></span>添加提醒
					</a>
				</h1>
			</div>
			<ul id="alert">
				<#if medic?exists>
					<#list medic.alert as al>
						<li class="list_each">
							<div class="double_item">
								<div class="delete">
									<span name="del" class="glyphicon glyphicon-remove"></span>
								</div>
								<div class="each">
									<span class="key">服用时间：</span>
									<span class="value">
										<input value="${al.alertTime}" name="alertTime" type="time" class="form-control"/>
									</span>
								</div>
								<div class="each">
									<span class="key">服用剂量：</span>
									<span class="value">
										<input name="amounts" value="${al.amounts}" type="number" class="form-control input"/>
										<#if item_index == 0>
											<select name="medicUnit" class="form-control select">
										<#else>
											<select disabled class="form-control select">
										</#if>
											<#if medic.medicUnit != "mg">
												<option value="mg">mg</option>
											<#else>
												<option value="mg" selected>mg</option>
											</#if>
											<#if medic.medicUnit != "g">
												<option value="g">g</option>
											<#else>
												<option value="g" selected>g</option>
											</#if>
											<#if medic.medicUnit != "ug">
												<option value="ug">ug</option>
											<#else>
												<option value="ug" selected>ug</option>
											</#if>
											<#if medic.medicUnit != "ml">
												<option value="ml">ml</option>
											<#else>
												<option value="ml" selected>ml</option>
											</#if>
											<#if medic.medicUnit != "U">
												<option value="U">U</option>
											<#else>
												<option value="U" selected>U</option>
											</#if>
											<#if medic.medicUnit != "WU">
												<option value="WU">WU</option>
											<#else>
												<option value="WU" selected>WU</option>
											</#if>
											<#if medic.medicUnit != "片">
												<option value="片">片</option>
											<#else>
												<option value="片" selected>片</option>
											</#if>
											<#if medic.medicUnit != "粒">
												<option value="粒">粒</option>
											<#else>
												<option value="粒" selected>粒</option>
											</#if>
											<#if medic.medicUnit != "支">
												<option value="支">支</option>
											<#else>
												<option value="支" selected>支</option>
											</#if>
											<#if medic.medicUnit != "喷">
												<option value="喷">喷</option>
											<#else>
												<option value="喷" selected>喷</option>
											</#if>
											<#if medic.medicUnit != "吸">
												<option value="吸">吸</option>
											<#else>
												<option value="吸" selected>吸</option>
											</#if>
											<#if medic.medicUnit != "瓶">
												<option value="瓶">瓶</option>
											<#else>
												<option value="瓶" selected>瓶</option>
											</#if>
											<#if medic.medicUnit != "袋">
												<option value="袋">袋</option>
											<#else>
												<option value="袋" selected>袋</option>
											</#if>
										</select>
									</span>
								</div>
							</div>
						</li>
					</#list>
				</#if>
				<#if medic?exists && (medic.alert?size>0)>
				<#else>
					<li class="list_each">
						<div class="double_item">
							<div class="delete">
								<span name="del" class="glyphicon glyphicon-remove"></span>
							</div>
							<div class="each">
								<span class="key">服用时间：</span>
								<span class="value">
									<input type="time" name="alertTime" class="form-control"/>
								</span>
							</div>
							<div class="each">
								<span class="key">服用剂量：</span>
								<span class="value">
									<input name="amounts" type="number" class="form-control input"/>
									<select name="medicUnit" class="form-control select">
										<option value="mg">mg</option>
										<option value="g">g</option>
										<option value="ug">ug</option>
										<option value="ml">ml</option>
										<option value="U">U</option>
										<option value="WU">WU</option>
										<option value="片">片</option>
										<option value="粒">粒</option>
										<option value="支">支</option>
										<option value="喷">喷</option>
										<option value="吸">吸</option>
										<option value="瓶">瓶</option>
										<option value="袋">袋</option>
									</select>
								</span>
							</div>
						</div>
					</li>
				</#if>
			</ul>
			<div class="hidden_area">
				<#if medic?exists>
					<input type="hidden" value="${medic.medicId}" name="medicId"/>
				</#if>
			</div>
			<div class="form-group login_reg_btn mar_top">
				<button id="submit"  class="btn btn-primary">保存修改</button>
			</div>
			</form>
		</div>
		<script>
			$(document).ready(function() {
				var last = 1;
				var alerts = $("#alert li");
				var del = $("span[name='del']");
				del.click(function(){
					last = alerts.length;
					if (last > 1 && del.index(this) != 0) {
						var index = del.index(this);
						alerts.eq(index).remove();
						last = last - 1;
					} else {
						if(last > 1){
							alert("亲！第一项不能删除");
						}else{
							alert("亲！只剩最后一项了哦");
						}
					}
				});
				$("#alert_click").click(function() {
					$("#alert").append(alert_info);
					alerts = $("#alert li");
					del = $("span[name='del']");
					last = alerts.length;
					del.unbind();
					del.click(function() {
						if (last > 1 && del.index(this) != 0) {
							var index = del.index(this);
							alerts.eq(index).remove();
							last = last - 1;
						} else {
							if(last > 1){
								alert("亲！第一项不能删除");
							}else{
								alert("亲！只剩最后一项了哦");
							}
						}
					});
				});
			});
		</script>
	</body>

</html>